package ltd.newbee.mall.controller.web;

import ltd.newbee.mall.common.Constants;
import ltd.newbee.mall.common.IndexConfigTypeEnum;
import ltd.newbee.mall.controller.vo.NewBeeMallIndexCarouselVO;
import ltd.newbee.mall.controller.vo.NewBeeMallIndexConfigGoodsVO;
import ltd.newbee.mall.entity.NewBeeMallGoods;
import ltd.newbee.mall.result.ResponseResultBody;
import ltd.newbee.mall.service.NewBeeMallCarouselService;
import ltd.newbee.mall.service.NewBeeMallGoodsService;
import ltd.newbee.mall.util.PageQueryUtil;
import ltd.newbee.mall.util.ResultGenerator;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.*;

import ltd.newbee.mall.service.NewBeeMallIndexConfigService;
import ltd.newbee.mall.util.PageQueryUtil;
import ltd.newbee.mall.util.Result;
import ltd.newbee.mall.util.ResultGenerator;

//import ltd.newbee.mall.result.ResponseResultBody
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods")
@ResponseResultBody
public class WebGoodsController {
    @Resource
    NewBeeMallCarouselService newBeeMallCarouselService;

    @Resource
    NewBeeMallGoodsService newBeeMallGoodsService;

    @PostMapping(value = "/list")
    @ResponseBody
    public Map list() throws Exception {
//        throw new Exception("wodesij");
        Map<String, Object> params = new HashMap<>();
        params.put("page", 1);
        params.put("limit", 20);

        PageQueryUtil pageUtil = new PageQueryUtil(params);
        newBeeMallGoodsService.test();
        System.out.println(newBeeMallGoodsService.test());
           return new HashMap() {{
            put("Carousel", newBeeMallCarouselService.getCarouselsForIndex(3));
            put("GoodsList", newBeeMallGoodsService.getNewBeeMallGoodsPage(pageUtil));
        }};
    }

    @PostMapping(value = "/goodDetailById")
    @ResponseBody
    public Object goodDetail(@RequestBody   Map<String,Integer> o) throws Exception{
        System.out.println("_______1");
        System.out.println(o.get("goodsId"));
        long id = o.get("goodsId");

        NewBeeMallGoods goods = newBeeMallGoodsService.getNewBeeMallGoodsById(id);
        return goods;
    }
}
